package com.ytc.controller;

import com.ytc.dto.CarDto;
import com.ytc.dto.CarTypeDto;
import com.ytc.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
public class EgoController {
    @Autowired
    private CarService carService;

    @RequestMapping("tobuy")
    public String tobuy(HttpServletRequest request){
        request.getSession().setAttribute("type1","");
        return "buy";
    }

    @RequestMapping("queryTypeToBuy")
    public String queryTypeToBuy(String type1, HttpServletRequest request){
        request.getSession().setAttribute("type1",type1);
        return "buy";
    }



    @RequestMapping("queryCarList")
    @ResponseBody
    public Map<String,Object> queryCarList(@RequestBody CarDto carDto){
        Map<String,Object> map = null;
        try {
            map = carService.queryCarList(carDto);
        }catch (Exception e){
            map = new HashMap();
            map.put("success",false);
            map.put("errMsg",e.getMessage());
        }
        return map;
    }
    @RequestMapping("getBrandnameList")
    @ResponseBody
    public Map<String,Object> getBrandnameList(){
        Map<String,Object> map = null;
        try {
            map = carService.getBrandnameList();
        }catch (Exception e){
            map = new HashMap();
            map.put("success",false);
            map.put("errMsg",e.getMessage());
        }
        return map;
    }
    @RequestMapping("togetType")
    @ResponseBody
    public Map<String,Object> getTypeList(Integer bandid){
        Map<String,Object> map = null;
        System.out.println(bandid+"5555555555555555555555555555555555");
        try {
            map = carService.getTypeList(bandid);
        }catch (Exception e){
            map = new HashMap();
            map.put("success",false);
            map.put("errMsg",e.getMessage());
        }
        return map;
    }

    @RequestMapping("toType")
    @ResponseBody
    public Map<String,Object> toType(Integer typeid){
        Map<String,Object> map = null;
        try {
            map = carService.toType(typeid);
        }catch (Exception e){
            map = new HashMap();
            map.put("success",false);
            map.put("errMsg",e.getMessage());
        }
        return map;
    }
}
